package me.militch.quickcore.di.module;

import android.app.Application;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.List;

import javax.inject.Singleton;

import dagger.Module;
import dagger.Provides;
import me.militch.quickcore.mvp.model.BaseModel;
import me.militch.quickcore.repository.IRepositoryStore;
import me.militch.quickcore.repository.IRepositoryStoreHelper;
import me.militch.quickcore.repository.RepositoryStore;
import quickcore.annotation.Repository;
import retrofit2.Retrofit;

/**
 * 全局配置Module
 */
@Module
public class GlobalConfigModule {
    private Application application;
    private List<Class> services;
    private RepositoryStore repositoryStore;
    private  IRepositoryStoreHelper iRepositoryStoreHelper;
    private GlobalConfigModule(GlobalConfigModule.Builder builder){
        this.application = builder.application;
        this.iRepositoryStoreHelper = builder.iRepositoryStoreHelper;
    }
    public static Builder builder(Application application){
        return new Builder(application);
    }
    @Provides
    @Singleton
    RepositoryStore provideRepositoryStore(Retrofit retrofit){
        RepositoryStore repositoryStore = new RepositoryStore(retrofit);
        iRepositoryStoreHelper.setRepository(repositoryStore);
        return repositoryStore;
    }

    public static class Builder{
        Application application;
        List<Class> services;
        private IRepositoryStoreHelper iRepositoryStoreHelper;
        private Builder(Application application){
            this.application = application;
        }
        public Builder setServices(List<Class> services) {
            this.services = services;
            return this;
        }
        public Builder setRepositoryStoreHelper(IRepositoryStoreHelper iRepositoryStoreHelper){
            this.iRepositoryStoreHelper = iRepositoryStoreHelper;
            return this;
        }
        public GlobalConfigModule build(){
            return new GlobalConfigModule(this);
        }
    }
}
